home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJTST111.ZIP / tests / t14.c < prev    next >
C/C++ Source or Header  |  1993-10-05  |  533b  |  31 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3.  
  4. main()
  5. {
  6.   FILE *f;
  7.   int fd;
  8.   char buf[10];
  9.   f = fopen("t14.dat", "w");
  10.   fwrite("abcdefghijklmnopqrstuvxyz\n", 26, 1, f);
  11.   fclose(f);
  12.  
  13.   fd = open("t14.dat", O_WRONLY|O_BINARY);
  14.   if (fd < 0)
  15.     return -1;
  16.   ftruncate(fd, 20);
  17.   close(fd);
  18.  
  19.   f = fopen("t14.dat", "r");
  20.   fread(buf, 5, 1, f);
  21.   buf[5] = 0;
  22.   printf("first pass: %s\n", buf);
  23.   rewind(f);
  24.   fread(buf, 5, 1, f);
  25.   buf[5] = 0;
  26.   printf("second pass: %s\n", buf);
  27.   fclose(f);
  28.  
  29.   return 0;  
  30. }
  31.